<template>
  <el-dialog title="分配角色" :visible.sync="roleDialog">
    <!-- 多选框组 -->
    <el-checkbox-group v-model="checkList">
      <el-checkbox v-for="item in roleList" :key="item.id" :label="item.id">{{
        item.name
      }}</el-checkbox>
    </el-checkbox-group>

    <!-- 放按钮 -->
    <div style="text-align: center;margin-top:20px;">
      <el-button @click="save" type="primary">确定</el-button>
      <el-button @click="roleDialog = false">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { assignRoleAPI } from '@/api/employees'
export default {
  data () {
    return {
      roleDialog: false,
      // 用来保存选中的角色
      checkList: [],
      // 用来保存所有角色
      roleList: [],
      id: ''
    }
  },
  methods: {
    async save () {
        const res = await assignRoleAPI({
            id: this.id,
            roleIds: this.checkList
        })
        // 弹出后端返回的提示
        this.$message.success(res.message)
        // 隐藏对话框
        this.roleDialog = false
    }
  }
}
</script>

<style></style>
